import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.Clip;
import javax.swing.*;
import java.io.File;

public class MusicStuff {
    void playMusic(String musicLocation) {
        try {
            File musicPath = new File(musicLocation);
            if(musicPath.exists()) {
                AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(musicPath);
                Clip clip = AudioSystem.getClip();
                clip.open(audioInputStream);
                clip.start();
                clip.loop(Clip.LOOP_CONTINUOUSLY);

//                JOptionPane.showMessageDialog(null,"按下暂停");
//                long clipTimePosition = clip.getMicrosecondPosition();
//                clip.stop();
//
//                JOptionPane.showMessageDialog(null,"按下继续");
//                clip.setMicrosecondPosition(clipTimePosition);
//                clip.start();

                JOptionPane.showMessageDialog(null,"按[确定]结束循环播放");
            }else {
                System.out.println("找不到文件");
            }
        }catch(Exception ex) {
            ex.printStackTrace();
        }
    }
}
